package com.campus.config.lifecycle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.campus.app.mapper.*;
import com.campus.app.service.CounsellorsService;
import com.campus.commons.entity.*;
import com.campus.commons.entity.Class;
import com.campus.config.cache.SignInCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 初始化类； 初始化一些信息
 * 这些方法就初始化的时候调一下， 更新咱们直接把更新的数据放进map中就可以了
 *
 */

@Component
public class CustomInit {

    //<editor-fold desc="自动装填的beans">
    @Autowired
    private WxIndexImageTypeMapper wxIndexImageTypeMapper;
    @Autowired
    private ClassMapper classMapper;

    @Autowired
    private ClassRoomMapper classRoomMapper;

    @Autowired
    private SemesterMapper semesterMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private DormMapper dormMapper;

    @Autowired
    private SkillTagMapper skillTagMapper;
    @Autowired
    private SkillTypeMapper skillTypeMapper;
    @Autowired
    private FeedTypeMapper feedTypeMapper;

@Autowired
private  AnnunciateTypeMapper annunciateTypeMapper;
@Autowired
private NotificationTypeMapper notificationTypeMapper;
@Autowired
private DepartmentsMapper departmentsMapper;
    @Autowired
    private CounsellorsService service;
    //</editor-fold>
    //初始化调用的方法
    @Scheduled(cron = "* * 0 * * ? ")
    public  void init() {
        setClassRoom();
//       设置班级map
        setTeacher();
        setSemester();
        setClass();
        setStudent();
        setSkillType();
        setDorm();
        setFeedType();
        setSkillTag();
        setAnnunciateType();
        setNotificationType();
        setDepartmentsMapper();
        //设置轮播页面类型
        setWxIndexImageType();
    }
    //<editor-fold desc="初始化方法">
    public void setFeedType() {
        FeedType.feeds= feedTypeMapper.selectList(null).stream().collect(Collectors.toMap(FeedType::getId,feedType -> feedType));
        System.out.println();
    }

    public void setWxIndexImageType() {
        WxIndexImageType.IndexTypes = wxIndexImageTypeMapper.selectList(null).stream().collect(Collectors.toMap(WxIndexImageType::getId, wxIndexImageType -> wxIndexImageType));
    }
    public void setDepartmentsMapper() {
       Departments.departmentsMap= departmentsMapper.selectList(null).stream().collect(Collectors.toMap(Departments::getId, departments -> departments));
    }
    public void setNotificationType() {
        NotificationType.types = notificationTypeMapper.selectList(null).stream().collect(Collectors.toMap(NotificationType::getId, notificationType -> notificationType));
    }
    public void setAnnunciateType() {
       AnnunciateType.annunciateTypeMap= annunciateTypeMapper.selectList(null).stream().collect(Collectors.toMap(AnnunciateType::getId,annunciateType -> annunciateType));
    }
    public    void setClass() {
        Map<Integer, Class> map = new HashMap<>();
        List<Class> classes = classMapper.selectList(null);
        for (Class c : classes) {
            map.put(c.getId(), c);
        }
        Class.classes = map;

    }
    public  void setClassRoom() {
        QueryWrapper<ClassRoom> queryWrapper = new QueryWrapper();
        Map<Integer, String> map = new HashMap<>();
        List<ClassRoom> classes = classRoomMapper.selectList(queryWrapper);
        for (ClassRoom c : classes) {
            map.put(c.getId(), c.getRoomname());
        }
        ClassRoom.classrooms = map;
    }
    public  void setSemester() {
        QueryWrapper<Semester> queryWrapper = new QueryWrapper();
        Map<Integer, String> map = new HashMap<>();
        List<Semester> classes = semesterMapper.selectList(queryWrapper);
        for (Semester c : classes) {
            map.put(c.getId(), c.getSemestername());
        }
        Semester.semester = map;
    }
    public  void setStudent() {
        QueryWrapper<Student> queryWrapper = new QueryWrapper();
        Map<Integer, Student> map = new HashMap<>();
        List<Student> classes = studentMapper.selectList(queryWrapper);
        for (Student c : classes) {
            map.put(c.getId(), c);
        }

        Student.students = map;

    }
    public  void setTeacher() {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper();
        Map<Integer, Teacher> map = new HashMap<>();
        List<Teacher> classes = teacherMapper.selectList(queryWrapper);
        for (Teacher c : classes) {
            map.put(c.getId(), c);
        }
        Teacher.teachers = map;
    }
    public void setDorm() {
        QueryWrapper<Dorm> queryWrapper = new QueryWrapper();
        Map<Integer, Dorm> map = new HashMap<>();
        List<Dorm> classes = dormMapper.selectList(queryWrapper);
        for (Dorm c : classes) {
            map.put(c.getId(), c);
        }
        Dorm.dorms = map;
    }
    public  void setSkillTag() {
        QueryWrapper<SkillTag> queryWrapper = new QueryWrapper();
        Map<Integer, SkillTag> map = new HashMap<>();
        List<SkillTag> classes = skillTagMapper.selectList(queryWrapper);
        for (SkillTag c : classes) {
            map.put(c.getId(), c);
        }
        SkillTag.skillTags = map;
    }
    public  void setSkillType() {
        QueryWrapper<SkillType> queryWrapper = new QueryWrapper();
        Map<Integer, SkillType> map = new HashMap<>();
        List<SkillType> classes = skillTypeMapper.selectList(queryWrapper);
        for (SkillType c : classes) {
            map.put(c.getId(), c);
        }
        SkillType.skillTagTypes = map;
    }
    //</editor-fold>



}
